﻿using System.Collections.Generic;
using System.Linq;
using SubSpec;
using Xunit;

namespace Ecos.GroceryList.AppService.Test
{
    public class GroceryListServiceTest
    {
        [Specification]
        public void QueryList()
        {
            var service = new GroceryListService();
            "Given: ".Context(() =>{
            });

            IEnumerable<string> activeList = null;
            "When: I want to query \"the list\"".Do(() =>
                activeList = service.QueryList());

            "Then: It will be return me all the items that has been added to the last active list on the GROCERY LIST REPOSITORY".Assert(() => {
                Assert.True(activeList.Count()==3);
                Assert.Contains("milk", activeList);
                Assert.Contains("eggs",activeList);
                Assert.Contains("pancake",activeList);
            });
        }

        [Specification]
        public void AddItem()
        {
            var service = new GroceryListService();
            var item = string.Empty;
            var countOfItemsBeforeAdding = default(int);
            "Given: An specified Item".Context(() =>{
                item = "lettuce";

                var activeListPreviousToTheAddCommand = service.QueryList();
                countOfItemsBeforeAdding = activeListPreviousToTheAddCommand.Count();
            });

            "When: I Add the Item".Do(() =>
                service.Add(item));

            "Then: It will be added to the last active list".Assert(() => {
                
                var activeList = service.QueryList();
                var countOfItemsAfterAdding = activeList.Count();
                Assert.Equal(countOfItemsBeforeAdding + 1,countOfItemsAfterAdding);

                Assert.Contains(item,activeList);
            });
        }

        [Fact]
        public void AddItem_AllListClosed()
        {
            //Given 
            //  An specified Item (and a username ¿and password? THAT HAS NO ACTIVE LISTS)
            //When 
            //  I Add the Item
            //Then 
            //  It will be create a new list and add the item to this list
        }

        [Fact]
        public void AddItem_NewUser()
        {
            //Given 
            //  An specified Item (and a username ¿and password? THAT DONT'T EXISTS)
            //When 
            //  I try to Add the Item
            //Then 
            //  The System launch a NoUserFoundException
        }

        [Fact]
        public void NewUser()
        {
            //Given 
            //  An username and a password
            //When 
            //  I Add new user
            //Then 
            //  The user was added to the system (how to probe this?)
        }

        [Fact]
        public void NewUserThatExists()
        {
            //Given 
            //  An username and a password (and the username already exists)
            //When 
            //  I try to Add new user
            //Then 
            //  The System launsh a UserExistsException
        }

        [Fact]
        public void QueryUser()
        {
            //Given 
            //  An username that already exists
            //When 
            //  I query for username
            //Then 
            //  The system returns true
        }

        [Fact]
        public void QueryUserThatNotExists()
        {
            //Given 
            //  An username that do not exists
            //When 
            //  I query for username
            //Then 
            //  The system returns false
        }

    }
}
